package com.alt.www.sort;

/**
 * Created by 27340 on 2017/9/16.
 */
public class Shell {
    public static void sort(Comparable[] a){
        //按升序排列
        int N = a.length;
        int h = 1;
        while (h < N/3) h = h*3 + 1;//1,4,13,40,121,364,1093......
        while (h >= 1){
            //将数组变为h有序
            for (int i = h; i<N ; i++) {
                for (int j = i; j >=h&&Example.less(a[j], a[j-h]) ; j-=h) {
                    Example.exch(a, j, j-h);
                }
            }
            h=h/3;
        }

    }
}
